import * as fs from "fs-extra"
import { IMAGEPATH, IMAGELENGTH } from "./Config"

class ImageManager {
    images: Array<string>
    constructor() {
        this.images = new Array(IMAGELENGTH);
        this.images[0] = require('../images/girls/0.png')
        this.images[1] = require('../images/girls/1.png')
        this.images[2] = require('../images/girls/2.png')
        // fs.readdir("..\\images\\girls", (err, files) => {
        //     this.images = files;
        //     console.log("ImageManager")
        //     console.log(this.images);
        // })
        // for (let i = 0; i < this.images.length; ++i) {
        //     this.images[i] = IMAGEPATH + this.images[i];
        // }
    }
    public size(): number {
        return this.images.length;
    }
    public get(index: number): string | null {
        if (index >= 0 && index < this.images.length) {
            return this.images[index];
        }
        return null;
    }

    public getByName(name: string): string {
        let val = 0;
        for (let i = 0; i < name.length; ++i) {
            val += name.charCodeAt(i);
        }
        val %= IMAGELENGTH;
        return this.images[val];
    }
}

let manager = new ImageManager();

export { manager }